(function (zn){

    zn.model = function (data){
        var Model = zn.class(zn.data.Observable, {
            properties: {
                owner: null
            },
            methods: {
                init: function (data){
                    this.sets(data);
                },
                set: function (name, value){
                    var _value = value;
                    console.log(_value);
                    if(this.has(name)){
                        if(value.defineProperty){
                            this.super(name, value);
                        }
                        else if(zn.is(value, 'object')){
                            console.log(value);
                            //zn.eacn()
                        }
                    }else {
                        this.defineProperty(name, value);
                    }
                },
                /*
                sets: function (){

                },*/
                defineProperty: function (name, value){
                    //console.log('define: '+name);
                    return this.constructor.defineProperty(name, {
                        value: this.parseValue(value)
                    });
                },
                parseValue: function (value){
                    return (zn.is(value, 'object')? zn.model(value): value) ;
                },
                save: function (){

                },
                toString: function (){

                }
            }
        });

        return new Model(data);
    }

    zn.GLOBAL.$model = zn.model({});
    //zn.GLOBAL.$view = zn.model({});

})(zn);
